<?php
/**
 *Controlador de envio de correos
 *@author Luis Gabriel Rodriguez <luisgabriel84@gmail.com>
 */

/**
 *Controlador de envio de correos
 */
class ContactController extends AppController
{
	var $name = 'Contact';
	var $uses = 'Contact';
        /**
        * @var array
        * @access public
        */
	var $helpers = array('Html', 'Form', 'Javascript','Flash');
        /**
        * @var array
        * @access public
        */
	var $components = array('Email', 'Session');

        function beforeFilter()
        {
            $this->Auth->allow('index');
        }

        /**
         * Funcion que envia el correo
         */
	function index(){

		if(isset($this->data)) {
			$this->Contact->create($this->data);

			if($this->Contact->validates()){

			    $this->data['Contact']['message'].= "\r\n".'---------------------------------------';
			    $this->data['Contact']['message'].= "\r\n".'Nombre:'.$this->data['Contact']['name'];
				$this->data['Contact']['message'].= "\r\n".'Empresa:'.$this->data['Contact']['empresa'];
			    $this->data['Contact']['message'].= "\r\n".'Email:'.$this->data['Contact']['email'];
				$this->data['Contact']['message'].= "\r\n".'Ciudad:'.$this->data['Contact']['ciudad'];
				$this->data['Contact']['message'].= "\r\n".'Dirigido a:'.$this->data['Contact']['dirigido'];
				$this->data['Contact']['message'].= "\r\n".'Movil:'.$this->data['Contact']['movil'];
				$this->Email->to = 'en.ruta@hotmail.com';//mail aqui
				$this->Email->replyTo = $this->data['Contact']['email'];
				$this->Email->from = $this->data['Contact']['name'].' <'.$this->data['Contact']['email'].'>';
				$this->Email->subject = 'Contacto a travez de pagina web';
				//$this->Email->delivery = 'debug';
				if ($this->Email->send($this->data['Contact']['message'])) {
					$this->Session->setFlash('Su Mensaje Fue Enviado');
					//$this->redirect('');
				} else {
					$this->Session->setFlash('No se pudo enviar el mail');
				}
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash('Por favor llene todos los campos');
				$this->redirect('/contacto');
			}
		}
	}

}
?>